package cn.bluemobi.app.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.bluemobi.app.core.mybatis.PageUtils;
import cn.bluemobi.app.entity.output.Commodity;
import cn.bluemobi.app.entity.output.Merchant;
import cn.bluemobi.app.mapper.CommodityMapper;
import cn.bluemobi.app.mapper.MerchantMapper;
import cn.bluemobi.app.service.MerchantService;
import cn.bluemobi.common.core.dto.Dto;
import cn.bluemobi.common.core.dto.Page;

/**
 * 
 * @author lvxh
 * 
 */
@Service
@Transactional
public class MerchantServiceImpl implements MerchantService {

	@Autowired
	private MerchantMapper merchantMapper;

	@Autowired
	private CommodityMapper commodityMapper;

	@Override
	public Page<Merchant> findMerchantList(Integer pageNo, Integer pageSize) {
		Page<Merchant> page = PageUtils.startPage(pageNo, pageSize);
		Map<String, Object> params = new HashMap<>();
		List<Merchant> merchants = merchantMapper.findMerchantList(params);
		page.setList(merchants);
		return page;
	}

	@Override
	public Dto<Merchant> findMerchantDetail(String memberId, String merchantId) {
		Dto<Merchant> dto = new Dto<Merchant>();
		Merchant merchant = merchantMapper.findMerchantDetail(merchantId,
				memberId);
		if (merchant != null) {
			Map<String, Object> params = new HashMap<>();
			params.put("merchantId", merchantId);
			List<Commodity> commodityList = commodityMapper
					.findCommodityList(params);
			merchant.setCommodityList(commodityList);
		}
		dto.setData(merchant);
		return dto;
	}
}
